package com.ruoyi.base.controller;

import com.ruoyi.base.domain.Build;
import com.ruoyi.base.service.IFloorBuildService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 楼座档案Controller
 *
 * @author ruoyi
 * @date 2024-06-03
 */
@RestController
@RequestMapping("/base/build")
@Api(tags = "楼座档案")
public class FloorBuildController extends BaseController {
    @Autowired
    private IFloorBuildService floorBuildService;

    /**
     * 查询楼座档案列表
     */
    @GetMapping("/list")
    @ApiOperation("查询楼座档案列表")
    public TableDataInfo<Build> list(Build build) {
        startPage();
        List<Build> list = floorBuildService.selectFloorBuildList(build);
        return getDataTable(list);
    }

    /**
     * 导出楼座档案列表
     */
    @Log(title = "楼座档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出楼座档案列表")
    public void export(HttpServletResponse response, Build build) {
        List<Build> list = floorBuildService.selectFloorBuildList(build);
        ExcelUtil<Build> util = new ExcelUtil<Build>(Build.class);
        util.exportExcel(response, list, "楼座档案数据");
    }

    /**
     * 获取楼座档案详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取楼座档案详细信息")
    public R<Build> getInfo(@PathVariable("id") String id) {
        return R.ok(floorBuildService.selectFloorBuildById(id));
    }

    /**
     * 新增楼座档案
     */
    @PreAuthorize("@ss.hasPermi('base:build:add')")
    @Log(title = "楼座档案", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增楼座档案")
    public AjaxResult add(@RequestBody Build build) {
        return toAjax(floorBuildService.insertFloorBuild(build));
    }

    /**
     * 修改楼座档案
     */
    @PreAuthorize("@ss.hasPermi('base:build:edit')")
    @ApiOperation("修改楼座档案")
    @Log(title = "楼座档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Build build) {
        return toAjax(floorBuildService.updateFloorBuild(build));
    }

    /**
     * 删除楼座档案
     */
    @PreAuthorize("@ss.hasPermi('base:build:remove')")
    @ApiOperation("删除楼座档案")
    @Log(title = "楼座档案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(floorBuildService.deleteFloorBuildByIds(ids));
    }
}
